-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Start warning on each use of a deprecated API #21939
feat: Start warning on each use of a deprecated API #21939
Conversation
Closes #21839 |
Note to self: add a test that calls deprecated API in a function and then call that function in a for-loop - verify that warning is only printed once. |
|
||
function warnOnDeprecatedApi(apiName, stack) { | ||
const stackLines = StringPrototypeSplit(stack, "\n"); | ||
ArrayPrototypeShift(stackLines); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why we shift one item here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to remove the Error\n
at the start of the output from new Error().stack
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if that's worth the cost of split
, shift
, and join
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest stack.slice(6)
with a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also suggest we should do that slice
at the line of "%cThis API was called from:\n" + stackString + "\n",
to minimize the overhead of this util
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also filtering irrelevant stack frames. Without it the stacks are very noisy and make it hard to figure out where the API is called. It's not like this API will be called in the hot path (and if it is it's yet another reason to fix user code quickly :))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will change the logic to first check if such stack traces was produced before manipulating the stack. Done.
runtime/js/99_main.js
Outdated
"%cWarning", | ||
"color: yellow; font-weight: bold;", | ||
); | ||
console.log( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I want it to stand out and be sore to the eyes :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea 😆
Should we also provide the option to mute these warnings by setting a |
Use API from |
Warn on each |
Waiting on #21961. Might want to add an env var after all - it might be useful in tests at least for the time being we still have these deprecated APIs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Nice!
@@ -728,6 +729,10 @@ impl CliOptions { | |||
} | |||
} | |||
|
|||
let disable_deprecated_api_warning = flags.log_level | |||
== Some(log::Level::Error) | |||
|| std::env::var("DENO_NO_DEPRECATION_WARNINGS").ok().is_some(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, this accepts DENO_NO_DEPRECATION_WARNINGS=0
. Is that deliberate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed this comment - yeah this is deliberate. We don't want to announce and encourage use of this env var - let's consider it for internal testing purposes. We want to "force" users to move away from these APIs.
"color: yellow;", | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should print the ability to disable these warnings with the DENO_NO_DEPRECATION_WARNINGS
environment variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow up to #21939 that adds deprecation warnings to more `Deno` APIs: - `Deno.copy()` - `Deno.iter()` - `Deno.iterSync()` - `new Deno.Buffer()` - `Deno.readAll()` - `Deno.readAllSync()` - `Deno.writeAll()` - `Deno.writeAllSync()` - `Deno.FsWatcher.return` - `Deno.serveHttp()` - `Deno.metrics()` --------- Signed-off-by: Asher Gomez <ashersaupingomez@gmail.com> Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit introduces deprecation warnings for "Deno.*" APIs.
This is gonna be quite noisy, but should tremendously help with user code updates to ensure
smooth migration to Deno 2.0. The warning is printed at each unique call site to help quickly
identify where code needs to be adjusted. There's some stack frame filtering going on to
remove frames that are not useful to the user and would only cause confusion.
The warning can be silenced using "--quiet" flag or "DENO_NO_DEPRECATION_WARNINGS" env var.
"Deno.run()" API is now using this warning. Other deprecated APIs will start warning
in follow up PRs.
Example:
Closes #21839